<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    class LRUCache {
      #map;
      #length;
      constructor(length) {
        this.#map = new Map();
        this.#length = length;
      }
      get(key){
        if(!this.#map.has(key)){
          return
        }
        const value = this.#map.get(key);
        this.#map.delete(key);
        this.#map.set(key,value);
        return value;
      }
      set(key,value){
        if(this.#map.has(key)){
          this.#map.delete(key);
        }
        this.#map.set(key,value);
        if(this.#map.size > this.#length){
          const firstKey = this.#map.keys().next().value;
          this.#map.delete(firstKey);
        }
      }
    }

    const cache = new LRUCache(5);
    cache.set(1, 1);
    cache.set(2, 2);
    cache.set(3, 3);
    cache.set(4, 4);
    cache.set(5, 5);
    cache.set(6, 6);
    console.log(cache);
  </script>
</body>
</html>